package cn.itcast.nems.listener.order;

import cn.itcast.nems.common.tenant.TenantInfo;
import cn.itcast.nems.common.tenant.TenantInfoHolder;
import cn.itcast.nems.listener.NemsMessageListener;
import cn.itcast.nems.order.dto.message.OrderCanceledMessageDTO;
import cn.itcast.nems.studentrecord.dto.OrderCanceledDTO;
import cn.itcast.nems.studentrecord.service.studentrecord.StudentRecordOrderService;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
/**
 * <p>
 * 订单取消息监听处理逻辑
 * </p>
 *
 * @author zhouwei
 * @since 2023/12/7 2:06 PM
 **/
@Component
@RequiredArgsConstructor
public class OrderCanceledMessageListener implements NemsMessageListener {
    private final static String TagName  =  "TAG_NEMS_ORDER_CANCELED" ;
    private final StudentRecordOrderService studentRecordOrderService ;

    @Override
    public String getTagName() {
        return TagName;
    }

    @Override
    public  void processMessage(String body) {
        OrderCanceledMessageDTO canceledDTO = JSON.parseObject(body, OrderCanceledMessageDTO.class);
        TenantInfoHolder.setTenantInfo(new TenantInfo(canceledDTO.getTenantId(), canceledDTO.getSubtenantId()));
        OrderCanceledDTO orderCanceledDTO = new OrderCanceledDTO();
        BeanUtils.copyProperties(canceledDTO, orderCanceledDTO);
        studentRecordOrderService.orderCanceled(orderCanceledDTO);
    }
}
